﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace autoshubiao
{
    internal class shijian
    {

        

        // 修改后的 SetTextBoxWatermark 方法
        public static void SetTextBoxWatermark(System.Windows.Forms.TextBox textBox, string watermarkText)
        {
            if (string.IsNullOrEmpty(textBox.Text))
            {
                textBox.Text = watermarkText;
                textBox.ForeColor = Color.Gray;  // 使用灰色显示水印
            }
        }

        // 事件处理方法


        public void textBox_Leave(object sender, EventArgs e)
        {
            System.Windows.Forms.TextBox textBox = sender as System.Windows.Forms.TextBox;
            if (textBox != null && string.IsNullOrEmpty(textBox.Text))
            {
                textBox.Text = "请输入文本...";
                textBox.ForeColor = Color.Gray;  // 使用灰色显示水印
            }
        }


        // 设置 ComboBox 水印
        public static void SetComboBoxWatermark(System.Windows.Forms.ComboBox comboBox, string watermarkText)
        {
            if (comboBox.Text == watermarkText)
            {
                comboBox.ForeColor = Color.Gray;
            }

            comboBox.GotFocus += (sender, e) =>
            {
                if (comboBox.Text == watermarkText)
                {
                    comboBox.Text = "";
                    comboBox.ForeColor = Color.Black;  // 恢复文本颜色
                }
            };

            comboBox.LostFocus += (sender, e) =>
            {
                if (string.IsNullOrEmpty(comboBox.Text))
                {
                    comboBox.Text = watermarkText;
                    comboBox.ForeColor = Color.Gray;  // 使用灰色显示水印
                }
            };
        }
    }
}
